home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1022 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. From: kanze@gabi-soft.fr (J. Kanze)
  2. Message-ID: <KANZE.96Apr10111924@gabi.gabi-soft.fr>
  3. X-Original-Date: 10 Apr 1996 09:19:24 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 10 Apr 96 11:20:18 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: C++ syntactic trap
  9. Organization: GABI Software, Sarl.
  10. References: <4k3q4p$lkd@syn.cs.cornell.edu> <4kcrhk$aj1@hermes.acs.unt.edu>
  11. In-Reply-To: johnw@jove.acs.unt.edu's message of 09 Apr 1996 09:59:37 PDT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMWuZeeEDnX0m9pzZAQGp6gF9FTRRzKNjaQDcCSyx5MxUUkU4gK+UwlQ8
  14.     PCoLabRUVxGZcWdxBvXaT2Wx6UzgGoxp
  15.     =vQPl
  16.  
  17. In article <4kcrhk$aj1@hermes.acs.unt.edu> johnw@jove.acs.unt.edu (John
  18. R. Williams) writes:
  19.  
  20.     [Concerning a warning for `new char( 10 )'...]
  21. |> I agree that it is uusual to allocate a single object of a built-in type 
  22. |> this way, but how do you propose to write this in such a way that such a 
  23. |> warning would not be generated? All I can think of is to warn when *any* 
  24. |> conversion occurs (this one looks pretty explicit to me), forcing you to 
  25. |> write something like this:
  26.  
  27. |>   char *foo = new char(static_cast<char>(10));
  28.  
  29. |> (Actually this rule doesn't seem too bad if applied only to built-in 
  30. |> types...)
  31.  
  32. Let's see:
  33.  
  34.     int*        pi = new int( static_cast< int >( 10 ) ) ;
  35.  
  36. Do you want the compiler to warn if you omit the static_cast (of int to
  37. int)? 
  38.  
  39. I do not think that I have a single instance of allocation of an array
  40. in any of my code.  Why should you make the most frequent case the most
  41. difficult.  (And allocating a single int is not that infrequent.  You
  42. might look at the implementation of counted_ptr in Barton and Nackman,
  43. for example.  It is certainly more frequent than allocating an array of
  44. int's, at least in well written C++ code.)
  45. -- 
  46. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  47. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  48. Conseils en informatique industrielle --
  49.                             -- Beratung in industrieller Datenverarbeitung
  50. ---
  51. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  52. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  53. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  54. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  55. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  56.